function line_dof = cr_indices(r,d,idx,pattern)
% to get the r's line of dofs of degree d parallel to edge i
% it is specially useful when treating smoothness condition and boundary
% condition! 
% the output parameter mat is the matrix P in my notes.
%
%
%
switch idx
    case 1
        line_dof = (((d+1-r)*(d-r)/2+1):((d+2-r)*(d+1-r)/2))';
    case -1
        line_dof = (((d+2-r)*(d+1-r)/2):-1:((d+1-r)*(d-r)/2+1))';
    case 2
        line_dof = pattern(r+1,1:d-r+1)';
    case -2
        line_dof = pattern(r+1,d-r+1:-1:1)';
    case 3
        line_dof = pattern(1:d-r+1,r+1);
    case -3
        line_dof = pattern(d-r+1:-1:1,r+1);
    otherwise
        line_dof = [];
end
%then put the corresponding value to a matrix;
% i = (1:d-r+1)';j = line_dof; s = ones(d-r+1,1);
% mat = sparse(i,j,s,d-r+1,(d+1)*(d+2)/2);
end